// pages/movie/movie.js
const globalObj = getApp();
import {
  theaters
} from '../../utils/home/hotMovie/index';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    aboveDistance: globalObj.globalData.aboveDistance,
    flag: 'hot',
    theatersList: [],
    startY: 0,
    moveDistance: 0,
    endY: 0,
    city: wx.getStorageSync('city'),
    pageY: 0,
    animationData: {},
    touchmoveY: 0
    // timer: null
  },
  changeMenu(e) {
    console.log(e)
    this.setData({
      flag: e.target.dataset.flag
    })
  },
  async getTheatersMovie() {
    let data = await theaters();
    console.log(data)
    this.setData({
      theatersList: data.data.data.list,
    })
  },
  scrollTouchstart(e) {
    // console.log('你碰到我了')
    this.setData({
      startY: e.touches[0].pageY,
      pageY: e.touches[0].pageY
    })
  },
  scrollTouchmove(e) {
    let h = e.touches[0].pageY - this.data.pageY;
    if (h > 0&& e.touches[0].pageY > this.data.touchmoveY && e.touches[0].pageY <= 600) {
      this.getAnimation(10, h + 'px');
      // console.log(this.data.touchmoveY, e.touches[0].pageY);
    }
    this.setData({
      touchmoveY: e.touches[0].pageY
    })    
  },
  scrollTouchend(e) {
    // this.scrollTouchmove = null;
    // console.log('结束', e)
    this.getAnimation(300, 0)
    // var w = wx.getSystemInfoSync().windowWidth;
    // var h = wx.getSystemInfoSync().windowHeight;
  },
  getAnimation(s, h) {
    let animation = wx.createAnimation({ //定义全局初始化动画
      duration: s, //定义动画持续的时间
      timingFunction: 'ease', //定义动画的进行
    })
    animation.translateY(h).step(); //移动距离
    this.setData({
      animationData: animation.export() //将定义的动画赋值给animationData
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getTheatersMovie();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})